import Util.JWTUtils;
import com.auth0.jwt.exceptions.AlgorithmMismatchException;
import com.auth0.jwt.exceptions.InvalidClaimException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.exceptions.TokenExpiredException;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.util.HashMap;

public class Main {
    public static void main(String[] args) {
        HashMap<String, Integer> user_info = new HashMap<String, Integer>();
        user_info.put("userId", 123);
//        DecodedJWT decodedJWT = JWTUtils.decode(JWTUtils.getToken(user_info));
//        Claim userName = decodedJWT.getClaim("userName");
//        Claim userId = decodedJWT.getClaim("userId");
//        System.out.println(userName.asString() + "," + userId.asString());
//        System.out.println(JWTUtils.getToken(user_info));
        System.out.println(JWTUtils.getToken(user_info));
        HashMap<String, Object> map = new HashMap<>();
        try {
            JWTUtils.verifyToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImNvbWVkeW1ha2VyIiwiZXhwIjoxNjY3MTM0MTUxLCJ1c2VySWQiOiIxMjMifQ.mKcf7ZLtsJmF29fHXPQnfhKokQIM0WqtzF_Oy6Yu1jE");
            return;
        }catch (SignatureVerificationException e) {
            e.printStackTrace();
            map.put("msg", "签名不一致异常");
        } catch (TokenExpiredException e) {
            e.printStackTrace();
            map.put("msg", "令牌过期异常");
        } catch (AlgorithmMismatchException e) {
            e.printStackTrace();
            map.put("msg", "算法不匹配异常");
        } catch (InvalidClaimException e) {
            e.printStackTrace();
            map.put("msg", "失效的payload异常");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("msg", "token无效");
        }
        return;

    }
}